﻿using System;

using UnityEngine;

namespace Gameplay.CharacterFramework 
{ 
    public abstract class Projectile:MonoBehaviour
    {
        protected Rigidbody _rb;

        protected Role _launcher;

        protected virtual void Awake()
        {
            if (!gameObject.TryGetComponent<Rigidbody>(out _rb))
            {
                Debug.LogWarning(gameObject.name + "未发现刚体");
            }
        }

        public virtual void SetLauncher(Role launcher)
        {
            _launcher = launcher;
        }
        public virtual void Shoot(Vector3 direction, float speed)
        {

        }

        protected virtual void OnTriggerEnter(Collider other)
        {
            if (other.TryGetComponent<Player>(out var player))
            {
                Vector3 closesPoint = other.ClosestPoint(transform.position);
                player.TakeDamage(_launcher,_launcher.SkillManager.CurrentConfig.DamageValue,closesPoint);
                Debug.Log("击中玩家");
                Destroy(this.gameObject);
            }
        }

        
    }
}
